package com.xquant.system.service.impl;

import java.util.List;

import com.xquant.system.api.domain.TsysInterfaceLog;
import com.xquant.system.mapper.TsysInterfaceLogMapper;
import com.xquant.system.service.ITsysInterfaceLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @author cloud
 * @version 1.0
 * @description:
 * @date 2022/4/22 15:17
 */
@Service
public class TsysInterfaceLogServiceImpl implements ITsysInterfaceLogService
{
    @Autowired
    private TsysInterfaceLogMapper tsysInterfaceLogMapper;

    /**
     * 查询导入日志
     *
     * @param id 主键
     * @return
     */
    @Override
    public TsysInterfaceLog selectTsysInterfaceLogById(String id)
    {
        return tsysInterfaceLogMapper.selectTsysInterfaceLogById(id);
    }

    @Override
    public List<TsysInterfaceLog> queryTsysInterfaceLogByICode(String iCode) {
        return tsysInterfaceLogMapper.selectTsysInterfaceLogByBusinNo(iCode);
    }

    /**
     * 查询列表
     *
     * @param tsysInterfaceLog 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<TsysInterfaceLog> selectTsysInterfaceLogList(TsysInterfaceLog tsysInterfaceLog)
    {
        return tsysInterfaceLogMapper.selectTsysInterfaceLogList(tsysInterfaceLog);
    }

    /**
     * 新增导入日志
     *
     * @param tsysInterfaceLog 新增导入日志
     * @return 结果
     */
    @Override
    public int insertTsysInterfaceLog(TsysInterfaceLog tsysInterfaceLog)
    {
        if(1 == tsysInterfaceLog.getUnique()){

            List<TsysInterfaceLog> logs = tsysInterfaceLogMapper.selectTsysInterfaceLogByBusinNo(tsysInterfaceLog.getBusinNo());

            logs.forEach(r->{
                if(r.getActionType() == tsysInterfaceLog.getActionType()){
                    tsysInterfaceLogMapper.deleteTsysInterfaceLogById(r.getId().toString());
                }
            });
        }
        return tsysInterfaceLogMapper.insertTsysInterfaceLog(tsysInterfaceLog);
    }

    /**
     * 修改导入日志
     *
     * @param tsysInterfaceLog 修改导入日志
     * @return 结果
     */
    @Override
    public int updateTsysInterfaceLog(TsysInterfaceLog tsysInterfaceLog)
    {
        return tsysInterfaceLogMapper.updateTsysInterfaceLog(tsysInterfaceLog);
    }

    /**
     * 批量删除导入日志
     *
     * @param ids 需要删除的导入日志主键
     * @return 结果
     */
    @Override
    public int deleteTsysInterfaceLogByIds(String[] ids)
    {
        return tsysInterfaceLogMapper.deleteTsysInterfaceLogByIds(ids);
    }

    /**
     * 删除导入日志信息
     *
     * @param id 导入日志主键
     * @return 结果
     */
    @Override
    public int deleteTsysInterfaceLogById(String id)
    {
        return tsysInterfaceLogMapper.deleteTsysInterfaceLogById(id);
    }

    @Override
    public int clearAll() {
        return tsysInterfaceLogMapper.clearTsysInterfaceLog();
    }
}
